#!/bin/bash
#

nginx_cmd=/usr/local/nginx/sbin/nginx
nginx_pid=/usr/local/nginx/logs/nginx.pid
if [ -z $1 ];then
	echo "help:$0 <start|stop|restart|status|reload>"
	exit 1
fi

case $1 in
	start)
		$nginx_cmd
		if [ $? -eq 0 ];then
			echo "nginx success"
		else
			echo "nginx failure"
		fi
	;;
	stop)
		$nginx_cmd -s stop
	;;
	restart)
		$nginx_cmd -s stop
		sleep 1
		$nginx_cmd
	;;
	status)
		if [ -f $nginx_pid ];then
			echo "nginx(PID $(cat $nginx_pid)) is running"
		else
			echo "nginx is stop"
		fi
	;;
	reload)
		kill -HUP $(cat $nginx_pid)
	;;
	*)
		echo "help:$0 <start|stop|restart|status|reload>"
	;;
esac
		
